package SingletonMode;

/**
 * @program: DesignModeProject
 * @description: 静态内部类
 * @author: Li canzhang
 * @create: 2022-04-12 10:33
 **/
public class SingletonTest07 {
    public static void main(String[] args) {
        Singleton07 inst1 = Singleton07.getInstance();
        Singleton07 inst2 = Singleton07.getInstance();

        System.out.println(inst1.hashCode());
        System.out.println(inst2.hashCode());
    }
    //静态内部类
    //当Singleton07被装载的时候  静态内部类SingletonInstance 不会被装载
    //当我们使用Singleton07.getInstance()时静态内部类SingletonInstance被装载，此时状态的过程时线程安全的
    static class Singleton07{
        private Singleton07(){}

        private static class SingletonInstance{
            private static final Singleton07 INST = new Singleton07();
        }
        public static Singleton07 getInstance(){
            return SingletonInstance.INST;
        }
    }
}
